package com.tianpengtech.front.web.common.util;

import com.jfinal.kit.Prop;
import com.jfinal.kit.PropKit;
import com.jfinal.kit.StrKit;
import com.jfinal.template.Engine;

import java.util.Map;

/**
 * Created by MaiSeries on 2017/5/31.
 */
public class WebPageUtil {

    public final String UTILNAME = "WebPageUtil";
    public final String LAYOUT_PATH = "/WEB-INF/view/web/_layout/_layout.html";
    private static final String WEBCONFIG = "web_config.properties";
    private static final String ENGINE_FIELD_PREFIX = "_web_";
    private Engine engine;

    public WebPageUtil(Engine engine){
        this.engine = engine;
    }

    public void loadPropToEngine(){
        Prop config = PropKit.use(WEBCONFIG);
        for (Map.Entry<Object, Object> entry : config.getProperties().entrySet()){
            engine.addSharedObject(ENGINE_FIELD_PREFIX+entry.getKey().toString(),entry.getValue().toString());
        }
    }

    public static String getUUID(){
        return StrKit.getRandomUUID();
    }
}
